﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Web;
using DHQGHN.DAL.BO.Online;
using DHQGHN.DAL.Models.Online;

namespace DHQGHN.Services.ONLINE
{
    public class OnlineService : IOnlineService
    {

        private OnlineBO onlineBO;
        #region Constructors
        public OnlineService()
        {

            onlineBO = new OnlineBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
        }
        #endregion

        public DAL.Models.DanhMuc.ADMINISTRATIVE_UNIT GetAdministrativeUnit(string code, string levels)
        {
            throw new NotImplementedException();
        }


        public int GenerateLoginCode(string province_code, string district_code, string commune_code, string IsResetAllGenerate)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return -1;
                }
                else
                {
                    return onlineBO.GenerateLoginCode(province_code, district_code, commune_code, IsResetAllGenerate);
                }

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public DAL.Models.Online.HouseDetail GetHouseDetailByLoginCode(string loginCode, string pin)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    DAL.Models.Online.HouseDetail asd = new HouseDetail();
                    return asd;
                }
                else
                {
                    return onlineBO.GetHouseDetailByLoginCode(loginCode, pin);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public string ResetLoginCodeHouseHold(string HouseHoldId)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return String.Empty;
                }
                else
                {
                    return onlineBO.ResetLoginCodeHouseHold(HouseHoldId);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public ReportModel Getreportall()
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    ReportModel hd = new ReportModel();
                    return hd;
                }
                else
                {
                    return onlineBO.Getreportall();
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public IEnumerable<ResidentDetail> GetResidentByLoginCode(string loginCode)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    List<ResidentDetail> hs = new List<ResidentDetail>();
                    return hs;
                }
                else
                {
                    return onlineBO.GetResidentByLoginCode(loginCode);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public LoginKhaiOnline GetLoginKhaiOnline(string loginCode)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    LoginKhaiOnline hs = new LoginKhaiOnline();
                    return hs;
                }
                else
                {
                    return onlineBO.GetLoginKhaiOnline(loginCode);
                }

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public List<DmEthnic> GetAllDmEthnic(string search)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    List<DmEthnic> hd = new List<DmEthnic>();
                    return hd;
                }
                else
                {
                    return onlineBO.GetAllDmEthnic(search);
                }

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public List<Resident1> OnlineSaveAndGetResident(HouseDetail update)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    List<Resident1> hs = new List<Resident1>();
                    return hs;
                }
                else
                {
                    return onlineBO.OnlineSaveAndGetResident(update);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public List<Resident1> GetbyRESIDENTbyHOUSEHOLD_ID(string HOUSEHOLD_ID)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    List<Resident1> hs = new List<Resident1>();
                    return hs;
                }
                else
                {
                    return onlineBO.GetbyRESIDENTbyHOUSEHOLD_ID(HOUSEHOLD_ID);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public List<Resident1> InsertOrUpdateResident1(List<Resident1> lst)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    List<Resident1> hs = new List<Resident1>();
                    return hs;
                }
                else
                {
                    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(lst);
                    return onlineBO.InsertOrUpdateResident1(json);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public void InsertOrUpdateResident2(List<Resident1> lst)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(lst);
                    onlineBO.InsertOrUpdateResident2(json);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public Khaisinh1Model UpdateThongTinCaNhan(DAL.Models.Online.ThongTinCaNhanModel thongtincanhan)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh1Model hs = new Khaisinh1Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateThongTinCaNhan(thongtincanhan);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateThongTinCaNhanNew(DAL.Models.Online.ThongTinCaNhanModel thongtincanhan)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateThongTinCaNhanNew(thongtincanhan);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThongTinChungModel UpdateThongTinCaNhanBack(DAL.Models.Online.ThongTinCaNhanModel thongtincanhan)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    ThongTinChungModel hs = new ThongTinChungModel();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateThongTinCaNhanBack(thongtincanhan);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh2Model UpdateKhaisinh1(DAL.Models.Online.Khaisinh1Model khaisinh1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh2Model hs = new Khaisinh2Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh1(khaisinh1);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateKhaisinh1New(DAL.Models.Online.Khaisinh1Model khaisinh1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateKhaisinh1New(khaisinh1);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThongTinCaNhanModel UpdateKhaisinh1Back(DAL.Models.Online.Khaisinh1Model khaisinh1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    ThongTinCaNhanModel hs = new ThongTinCaNhanModel();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh1Back(khaisinh1);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh3Model UpdateKhaisinh2(DAL.Models.Online.Khaisinh2Model khaisinh2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh3Model hs = new Khaisinh3Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh2(khaisinh2);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateKhaisinh2New(DAL.Models.Online.Khaisinh2Model khaisinh2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateKhaisinh2New(khaisinh2);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh1Model UpdateKhaisinh2Back(DAL.Models.Online.Khaisinh2Model khaisinh2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh1Model hs = new Khaisinh1Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh2Back(khaisinh2);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh4Model UpdateKhaisinh3(DAL.Models.Online.Khaisinh3Model khaisinh3)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh4Model hs = new Khaisinh4Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh3(khaisinh3);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateKhaisinh3New(DAL.Models.Online.Khaisinh3Model khaisinh3)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateKhaisinh3New(khaisinh3);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh2Model UpdateKhaisinh3Back(DAL.Models.Online.Khaisinh3Model khaisinh3)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh2Model hs = new Khaisinh2Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh3Back(khaisinh3);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TinhTrangHonNhanModel UpdateKhaisinh4(DAL.Models.Online.Khaisinh4Model khaisinh4)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    TinhTrangHonNhanModel hs = new TinhTrangHonNhanModel();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh4(khaisinh4);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateKhaisinh4New(DAL.Models.Online.Khaisinh4Model khaisinh4)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateKhaisinh4New(khaisinh4);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh3Model UpdateKhaisinh4Back(DAL.Models.Online.Khaisinh4Model khaisinh4)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh3Model hs = new Khaisinh3Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateKhaisinh4Back(khaisinh4);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru1Model UpdateTinhTrangHonNhan(DAL.Models.Online.TinhTrangHonNhanModel tthn)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    ThuongTru1Model hs = new ThuongTru1Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateTinhTrangHonNhan(tthn);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateTinhTrangHonNhanNew(DAL.Models.Online.TinhTrangHonNhanModel tthn)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateTinhTrangHonNhanNew(tthn);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh4Model UpdateTinhTrangHonNhanBack(DAL.Models.Online.TinhTrangHonNhanModel tthn)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    Khaisinh4Model hs = new Khaisinh4Model();
                    return hs;
                }
                else
                {
                    return onlineBO.UpdateTinhTrangHonNhanBack(tthn);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru2Model UpdateThuongTru1(DAL.Models.Online.ThuongTru1Model tt1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThuongTru2Model();
                }
                else
                {
                    return onlineBO.UpdateThuongTru1(tt1);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateThuongTru1New(DAL.Models.Online.ThuongTru1Model tt1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateThuongTru1New(tt1);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TinhTrangHonNhanModel UpdateThuongTru1Back(DAL.Models.Online.ThuongTru1Model tt1)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new TinhTrangHonNhanModel();
                }
                else
                {
                    return onlineBO.UpdateThuongTru1Back(tt1);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TheCanCuocModel UpdateThuongTru2(DAL.Models.Online.ThuongTru2Model tt2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new TheCanCuocModel();
                }
                else
                {
                    return onlineBO.UpdateThuongTru2(tt2);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateThuongTru2New(DAL.Models.Online.ThuongTru2Model tt2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateThuongTru2New(tt2);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru1Model UpdateThuongTru2Back(DAL.Models.Online.ThuongTru2Model tt2)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThuongTru1Model();
                }
                else
                {
                    return onlineBO.UpdateThuongTru2Back(tt2);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public HoChieuModel UpdateTheCanCuoc(DAL.Models.Online.TheCanCuocModel tcc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new HoChieuModel();
                }
                else
                {
                    return onlineBO.UpdateTheCanCuoc(tcc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateTheCanCuocNew(DAL.Models.Online.TheCanCuocModel tcc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateTheCanCuocNew(tcc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru2Model UpdateTheCanCuocBack(DAL.Models.Online.TheCanCuocModel tcc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThuongTru2Model();
                }
                else
                {
                    return onlineBO.UpdateTheCanCuocBack(tcc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LevelModel UpdateHoChieu(DAL.Models.Online.HoChieuModel hc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LevelModel();
                }
                else
                {
                    return onlineBO.UpdateHoChieu(hc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateHoChieuNew(DAL.Models.Online.HoChieuModel hc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateHoChieuNew(hc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TheCanCuocModel UpdateHoChieuBack(DAL.Models.Online.HoChieuModel hc)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new TheCanCuocModel();
                }
                else
                {
                    return onlineBO.UpdateHoChieuBack(hc);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public InsuranceModel UpdateMedicine(MedicineModel medicine)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new InsuranceModel();
                }
                else
                {
                    return onlineBO.UpdateMedicine(medicine);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateMedicineNew(MedicineModel medicine)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateMedicineNew(medicine);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LaborAndJobModel UpdateMedicineBack(MedicineModel medicine)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LaborAndJobModel();
                }
                else
                {
                    return onlineBO.UpdateMedicineBack(medicine);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ChetMatTichModel UpdateInsurance(InsuranceModel insurance)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ChetMatTichModel();
                }
                else
                {
                    return onlineBO.UpdateInsurance(insurance);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateInsuranceNew(InsuranceModel insurance)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateInsuranceNew(insurance);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public MedicineModel UpdateInsuranceBack(InsuranceModel insurance)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new MedicineModel();
                }
                else
                {
                    return onlineBO.UpdateInsuranceBack(insurance);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LaborAndJobModel UpdateLevel(LevelModel level)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LaborAndJobModel();
                }
                else
                {
                    return onlineBO.UpdateLevel(level);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateLevelNew(LevelModel level)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateLevelNew(level);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public HoChieuModel UpdateLevelBack(LevelModel level)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new HoChieuModel();
                }
                else
                {
                    return onlineBO.UpdateLevelBack(level);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public MedicineModel UpdateLaborAndJob(LaborAndJobModel laborJob)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new MedicineModel();
                }
                else
                {
                    return onlineBO.UpdateLaborAndJob(laborJob);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public void UpdateLaborAndJobNew(LaborAndJobModel laborJob)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateLaborAndJobNew(laborJob);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LevelModel UpdateLaborAndJobBack(LaborAndJobModel laborJob)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LevelModel();
                }
                else
                {
                    return onlineBO.UpdateLaborAndJobBack(laborJob);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        public void UpdateChetMattich(ChetMatTichModel cm)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                }
                else
                {
                    onlineBO.UpdateChetMattich(cm);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        public InsuranceModel UpdateChetMattichBack(ChetMatTichModel cm)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new InsuranceModel();
                }
                else
                {
                    return onlineBO.UpdateChetMattichBack(cm);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThongTinChungModel GetThongtinchung(string residentId)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThongTinChungModel();
                }
                else
                {
                    return onlineBO.GetThongtinchung(residentId);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThongTinCaNhanModel GetThongtincanhan(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThongTinCaNhanModel();
                }
                else
                {
                    return onlineBO.GetThongtincanhan(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh1Model GetKhaisinh1(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new Khaisinh1Model();
                }
                else
                {
                    return onlineBO.GetKhaisinh1(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh2Model GetKhaisinh2(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new Khaisinh2Model();
                }
                else
                {
                    return onlineBO.GetKhaisinh2(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh3Model GetKhaisinh3(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new Khaisinh3Model();
                }
                else
                {
                    return onlineBO.GetKhaisinh3(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public Khaisinh4Model GetKhaisinh4(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new Khaisinh4Model();
                }
                else
                {
                    return onlineBO.GetKhaisinh4(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TinhTrangHonNhanModel GetTinhtranghonnhan(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new TinhTrangHonNhanModel();
                }
                else
                {
                    return onlineBO.GetTinhtranghonnhan(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru1Model GetThuongtru1(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThuongTru1Model();
                }
                else
                {
                    return onlineBO.GetThuongtru1(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ThuongTru2Model GetThuongtru2(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ThuongTru2Model();
                }
                else
                {
                    return onlineBO.GetThuongtru2(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public TheCanCuocModel GetThecancuoc(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new TheCanCuocModel();
                }
                else
                {
                    return onlineBO.GetThecancuoc(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public HoChieuModel GetHochieu(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new HoChieuModel();
                }
                else
                {
                    return onlineBO.GetHochieu(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LevelModel GetLevel(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LevelModel();
                }
                else
                {
                    return onlineBO.GetLevel(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public LaborAndJobModel GetLabor(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new LaborAndJobModel();
                }
                else
                {
                    return onlineBO.GetLabor(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public MedicineModel GetMedicine(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new MedicineModel();
                }
                else
                {
                    return onlineBO.GetMedicine(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public InsuranceModel GetInsurance(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new InsuranceModel();
                }
                else
                {
                    return onlineBO.GetInsurance(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        public ChetMatTichModel GetChetvaMattich(TTCOM a)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new ChetMatTichModel();
                }
                else
                {
                    return onlineBO.GetChetvaMattich(a);
                }

            }
            catch (Exception ex)
            {
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        #region Print login code

        #endregion



        public List<DAL.Models.TDT.HOUSEHOLD2> SearchPrintCodeHouseHold(SearchPrintCodeHouseHold search)
        {
            try
            {
                return onlineBO.SearchPrintCodeHouseHold(search);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public HouseDetail InsertOrUpdateResidentAndGetHouseHold(List<Resident1> lst)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return new HouseDetail();
                }
                else
                {
                    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(lst);
                    return onlineBO.InsertOrUpdateResidentAndGetHouseHold(json);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public string SubmitComplete(string HouseHoldId)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return String.Empty;
                }
                else
                {
                    return onlineBO.SubmitComplete(HouseHoldId);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public string OnlineSaveHousehold(HouseDetail update)
        {
            try
            {
                if (!RoleChecking.CanAccess(WebOperationContext.Current.IncomingRequest.Headers))
                {
                    RoleChecking.ThrowUnauthorizedException();
                    return String.Empty;
                }
                else
                {
                    onlineBO.OnlineSaveHousehold(update);
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {

                return ex.Message;
            }
        }
    }
}